package controller;

import entity.Cat;
import service.CatService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/buy")
public class BuyController extends HttpServlet {
    CatService catService=new CatService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 后端获取前端传来的参数
        String id=req.getParameter("id");
        // 根据宠物猫id查询宠物猫信息，并且将电影信息传输给页面
        String sql="select * from cat where id=?";
        Cat cat=catService.getCatById(sql,id);
        // 将查询数据传输给前端
        req.setAttribute("cat",cat);
        // 跳转到详情页面detail.jsp
        req.getRequestDispatcher("view/buy.jsp").forward(req,resp);

    }
}
